
#include "TextTexture.h"

extern "C" int wrCreateTextTexture(const char *str, const char *fontName, float fontSize, int _iHAlign, int _iVAlign, int *_iWidth, int *_iHeight, int *_iTextWidth, int *iTextHeight, bool _bBreakLines, int _iLineWidth);
extern "C" int wrDeleteTextTexture(int _iTextureID);

TextTexture::TextTexture(const std::string &_sText, const std::string &_sFontName, float _fFontSize, int _iHAlign, int _iVAlign, bool _bBreakLines, int _iLineWidth)
{
    texture_id = -1;
    
	m_sText = _sText;
    m_sFontName = _sFontName;
    m_fFontSize = _fFontSize;
    m_iHAlign = _iHAlign;
    m_iVAlign = _iVAlign;
    m_bBreakLines = _bBreakLines;
    m_iLineWidth = _iLineWidth;
    
	createTextTexture();
}

void TextTexture::setText( const std::string &_sText )
{
	if( m_sText != _sText)
	{
		m_sText = _sText;
		createTextTexture();
	}
}

void TextTexture::createTextTexture()
{
    if(texture_id != -1)
        wrDeleteTextTexture(texture_id);
    
    int iWidth, iHeight, iTextWidth, iTextHeight;
	texture_id = wrCreateTextTexture(m_sText.c_str(), m_sFontName.c_str(), m_fFontSize, m_iHAlign, m_iVAlign, &iWidth, &iHeight, &iTextWidth, &iTextHeight, m_bBreakLines, m_iLineWidth);
    m_vSize = Vector2(iWidth, iHeight);
    m_vTextSize = Vector2(iTextWidth, iTextHeight);
}
